package com.rgs.se.singleton;

import java.util.Objects;

/**
 * @author Ren Gaoshuai
 * @ClassName TestSingleton5
 * @Description 懒汉式 双重校验
 * @date 2021-09-02 10:04
 **/
public class TestSingleton5 {

    private volatile static TestSingleton5 instance;
    private TestSingleton5(){}

    public static TestSingleton5 getInstance() {
        if (Objects.isNull(instance)) {
            synchronized (TestSingleton5.class) {
                if (Objects.isNull(instance)) {
                    //这句，不是原子操作，JVM内部可能会对其指令重排，使用volatile关键字，进制指令重排
                    instance = new TestSingleton5();
                }
            }
        }
        return instance;
    }
}
